package com.huawei.hwid.api.common;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.huawei.cloudservice.CloudRequestHandler;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.helper.handler.ErrorStatus;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;

class i extends SafeBroadcastReceiver {
    private Context a;
    private CloudRequestHandler b;
    private boolean c = false;

    public i(Context context, CloudRequestHandler cloudRequestHandler) {
        this.a = context;
        this.b = cloudRequestHandler;
    }

    public void onReceiveMsg(Context context, Intent intent) {
        if (!this.c) {
            Bundle bundle;
            try {
                bundle = new Bundle();
                bundle.putBoolean("FingerBroadcastReceiver", true);
                e.a(this.a, bundle);
            } catch (IllegalArgumentException e) {
                e.c("FingerBroadcastReceiver", "IllegalArgumentException", true);
            }
            this.c = true;
            if (intent != null) {
                String action = intent.getAction();
                e.d(context);
                try {
                    if ("com.huawei.cloudserive.fingerSuccess".equals(action)) {
                        if (this.b != null) {
                            e.a(context, intent);
                            bundle = intent.getBundleExtra(HwAccountConstants.EXTRA_BUNDLE);
                            if (bundle == null) {
                                bundle = new Bundle();
                            }
                            this.b.onFinish(bundle);
                        }
                    } else if ("com.huawei.cloudserive.fingerCancel".equals(action)) {
                        ErrorStatus errorStatus = new ErrorStatus(3002, "use the sdk: press cancel or back key");
                        if (this.b != null) {
                            this.b.onError(errorStatus);
                        }
                    }
                } catch (RuntimeException e2) {
                    e.b("FingerBroadcastReceiver", "BroadcastReceiver components are not allowed to register to receive intents", true);
                }
            }
        }
    }
}
